package com.sdp.wx.controller;


import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.wx.db.wx_supervision_feedback.entity.WxSupervisionFeedback;
import com.sdp.wx.db.wx_supervision_feedback.service.IWxSupervisionFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2024-02-21
 */
@RestController
@RequestMapping("/WxSupervisionFeedbackController")
public class WxSupervisionFeedbackController {
    @Autowired
    private IWxSupervisionFeedbackService iWxSupervisionFeedbackService;

    @Autowired
    private Query query;

    @PostMapping(value = "/page")
    public Result<?> page(@RequestBody DataCenter dataCenter) {
        return Result.ok(query.page(iWxSupervisionFeedbackService, WxSupervisionFeedback.class, dataCenter));
    }

    @PostMapping(value = "/save")
    @Transactional(rollbackFor=Exception.class)
    public Result<?> save(@RequestBody WxSupervisionFeedback wxSupervisionFeedback) {
        if(wxSupervisionFeedback==null) {
            return Result.error("反馈信息为空");
        }
        if(StringUtils.isEmpty(wxSupervisionFeedback.getKeyId())) {
            iWxSupervisionFeedbackService.save(wxSupervisionFeedback);
        }else {
            iWxSupervisionFeedbackService.updateById(wxSupervisionFeedback);
        }
        return Result.ok();
    }
}

